package com.szzg10.webservice.chapter5;

import java.io.IOException;
import java.net.URL;
import java.security.cert.Certificate;

import javax.net.ssl.HttpsURLConnection;

public class SunClient {

	private final String str_url = "https://www.google.com.hk/";
	
	public static void main(String[] args) throws IOException {
		new SunClient().doIn();
	}
	
	private void doIn() throws IOException {
		URL url = new URL(str_url);
		
		HttpsURLConnection conn = (HttpsURLConnection)url.openConnection();
		conn.setDoInput(true);
		conn.setDoOutput(true);
		conn.connect();
		
		dump_features(conn);
	}
	
	private void dump_features(HttpsURLConnection conn) throws IOException {
		System.out.println("Response Code: " + conn.getResponseCode());
		System.out.println("Cipher Suite: " + conn.getCipherSuite());
		
		Certificate[] certificates = conn.getServerCertificates();
		for(Certificate element: certificates) {
			System.out.println("Type: " + element.getType());
			System.out.println("Hash Code: " +element.hashCode());
			System.out.println("Algorithm: " + element.getPublicKey().getAlgorithm());
			System.out.println("Format: " + element.getPublicKey().getFormat());
			System.out.println();
		}
	}
}
